﻿namespace Cube.Data
{
    class Block
    {
        public PositionVector Position { get; set; }
        public ColorVector ColorVector { get; set; }
        public Block(PositionVector position, ColorVector color)
        {
            Position = position;
            ColorVector = color;
        }
        public void Rotate(Dimention d, int step)
        {
            int i;
            switch (d)
            {
                case Dimention.X:
                    for (i = 0; i < step; i++)
                    {
                        Position.RotateX();
                        ColorVector.RotateX();
                    }
                    break;
                case Dimention.Y:
                    for (i = 0; i < step; i++)
                    {
                        Position.RotateY();
                        ColorVector.RotateY();
                    }
                    break;
                case Dimention.Z:
                    for (i = 0; i < step; i++)
                    {
                        Position.RotateZ();
                        ColorVector.RotateZ();
                    }
                    break;
            }
        }

        public Block Clone()
        {
            var position = new PositionVector(Position.X, Position.Y, Position.Z);
            var color = new ColorVector(ColorVector.X, ColorVector.Y, ColorVector.Z);
            return new Block(position, color);
        }
    }

    /// <summary>
    /// 坐标向量
    /// </summary>
    class PositionVector
    {
        public int X { get; set; }
        public int Y { get; set; }
        public int Z { get; set; }
        public PositionVector(int x,int y,int z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        public void RotateX()
        {
            int y = -Z;
            int z = Y;
            Y = y;
            Z = z;
        }
        public void RotateY()
        {
            int x = Z;
            int z = -X;
            X = x;
            Z = z;
        }
        public void RotateZ()
        {
            int x = -Y;
            int y = X;
            X = x;
            Y = y;
        }
        public override bool Equals(object obj)
        {
            var position = (PositionVector)obj;
            if (position.X == X && position.Y == Y && position.Z == Z) return true;
            return false;
        }
    }

    /// <summary>
    /// 颜色向量
    /// </summary>
    class ColorVector
    {
        public CubeColor X { get; set; }
        public CubeColor Y { get; set; }
        public CubeColor Z { get; set; }
        public ColorVector(CubeColor x,CubeColor y,CubeColor z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        public override bool Equals(object obj)
        {
            var result = true;
            var color = (ColorVector)obj;
            var x = color.X;
            var y = color.Y;
            var z = color.Z;
            if (x != X && x != Y && x != Z) result = false;
            if (y != X && y != Y && y != Z) result = false;
            if (z != X && z != Y && z != Z) result = false;
            return result;
        }
        public void RotateX()
        {
            var temp = Y;
            Y = Z;
            Z = temp;
        }
        public void RotateY()
        {
            var temp = Z;
            Z = X;
            X = temp;
        }
        public void RotateZ()
        {
            var temp = X;
            X = Y;
            Y = temp;
        }
    }

    /// <summary>
    /// 维度枚举
    /// </summary>
    enum Dimention
    {
        X,
        Y,
        Z
    }

    /// <summary>
    /// 颜色枚举
    /// </summary>
    enum CubeColor
    {
        Blue,
        Green,
        Orange,
        Red,
        White,
        Yellow,
        /// <summary>
        /// 无颜色
        /// </summary>
        None
    }
}
